package org.eclipse.pde.toolbox.adaptors.internal;

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.Vector;

public class PluginFactory implements ITreeNode {

	private String name;
	private PluginAdapter[] adapterNames;
	private Vector<String> children;
	private NamespaceParent parent;

	public PluginFactory(String name,NamespaceParent parent, Collection children) {
		this.name = name;
		this.parent=parent;
		Set ch = new HashSet(children);

		this.children = new Vector<String>();

		for (Iterator it = ch.iterator(); it.hasNext();) {
			this.children.add((String) it.next());
		}
	}

	@Override
	public ITreeNode getParent() {
		// TODO Auto-generated method stub
		return parent;
	}

	@Override
	public boolean hasChildren() {
		// TODO Auto-generated method stub

		return !children.isEmpty();
	}

	@Override
	public ITreeNode[] getChildren() {
		// TODO Auto-generated method stub
		adapterNames = new PluginAdapter[children.size()];
		for (int i = 0; i < children.size(); i++) {
			adapterNames[i] = new PluginAdapter(children.get(i), this,parent.toString());
		}
		return adapterNames;
	}

	public String toString() {
		return "adaptable type: "+this.name;
	}

	@Override
	public String getDescription() {
		// TODO Auto-generated method stub
		return this.name;
	}

}
